/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * httpd
 * Copyright (C) Dnyanesh Gate 2012 <dnyaneshgate@yahoo.com>
 * 
 * httpd is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * httpd is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __SOCKET_H__
#define __SOCKET_H__

#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>					/* hostent struct, gethostbyname() */
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>				/* inet_ntoa() to format IP address */
#include <netinet/in.h>				/* in_addr structure */
#include <Common.h>

#define BUFFSIZE 4096
#define MAXCLIENTS 1000

class Socket {
	private:
		
	protected:
		int SOCK;
		struct sockaddr_in serv_addr;
		
	public:
		Socket();
		~Socket();
		
		int Connect(const char* addr, int port);
		int CloseSocket();
		int Send(const char* str, int size);
		int Recv(char* str);
		int SetSockOpt(int level, int optname, const void *optval,socklen_t optlen);
		int GetSockOpt(int level, int optname, void *optval,socklen_t *optlen);
};

class ServerSocket : public Socket {
	private:
		int noOfclients;
		int CLIENT[MAXCLIENTS];
		struct sockaddr_in cli_addr[MAXCLIENTS];
		
	protected:
		
		
	public:
		ServerSocket();
		~ServerSocket();
		
		int Bind(int port);
		int Listen();
		int Accept(int i);
		int Send(const char* str,int size, int i);
		int Recv(char* str,int i);
		int CloseConnection(int i);
};

#endif	//__SOCKET_H__
